$(function(){
	//if($.cookie('JSESSIONID')==null) window.location.href="index.html";
	var table = document.createElement("table");
	table.setAttribute("width", "100%");
	var row = table.insertRow();
	var cell = row.insertCell();
	cell.align="left";
	if($.cookie('ISADMIN')==true) 
		cell.innerHTML = '<font size="2" color="black">你好，管理员 '+$.cookie('NAME') +'('+$.cookie('PHONE') +')</font>';
	else 
		cell.innerHTML = '<font size="2" color="black">你好，'+$.cookie('NAME') +'('+$.cookie('PHONE') +')</font>';
	cell = row.insertCell();
	cell.align="right";
	
	cell.innerHTML = '<a onclick="logout()" style="cursor:pointer;"><font size="2" color="red">退出系统</font></a>';
	$('#north').append(table);
});

function logout(){
	$.cookie('JSESSIONID',null,{ path: '/' });
    $.cookie('PHONE',null,{ path: '/' });
    $.cookie('NAME',null,{ path: '/' });
    $.cookie('ISADMIN',null,{ path: '/' });
    $.cookie('ISASSISTANT',null,{ path: '/' });
    window.location.href="index.html";
}

function menuHandler(item){
	if(item.name == "refresh"){
		var currentTab = $('#tt').tabs('getSelected');
		var url = $(currentTab.panel('options').content).attr('src');
		$('#tt').tabs('update', {
	    	tab : $('#tt').tabs('getSelected'),
	    	options : {
	    		content : createFrame(url)
	    	}
	    });
    }else if(item.name == "closeall"){
    	var closeTabsTitle = [];
    	for (var i = 0; i < $('#tt').tabs('tabs').length; i++){
    		var op = $('#tt').tabs('getTab',i).panel('options');
    		if (op.closable) closeTabsTitle.push(op.title);
    	}
    	for (var i = 0; i < closeTabsTitle.length; i++) $('#tt').tabs("close", closeTabsTitle[i]);
    }else if(item.name == "closeoth"){
    	var name = $('#tt').tabs('getSelected').panel('options').title;
    	var closeTabsTitle = [];
    	for (var i = 0; i < $('#tt').tabs('tabs').length; i++){
    		var op = $('#tt').tabs('getTab',i).panel('options');
    		if (op.closable && op.title != name) closeTabsTitle.push(op.title);
    	}
    	for (var i = 0; i < closeTabsTitle.length; i++) $('#tt').tabs("close", closeTabsTitle[i]);
    	$('#tt').tabs('select',name);
    }else if(item.name == "close") $('#tt').tabs('close',$('#tt').tabs('getSelected').panel('options').title);
}

function addtab(url,title){
	var tab=$('#tt').tabs('exists',title);
	if(tab){
		$('#tt').tabs('select',title);
		$('#tt').tabs('update', {
	    	tab : $('#tt').tabs('getSelected'),
	    	options : {
	    		content : createFrame(url)
	    	}
	    });
	}else{
		var content = createFrame(url);
		$('#tt').tabs('add',{
			title:title,
			content:content,
			closable:true
		});
	}
	$('#tt').bind('contextmenu',function(e){
        e.preventDefault();
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    });
}

function createFrame(url){
	var content = "<iframe width='100%' height='99.6%'  id='iframe' frameborder='0' scrolling='auto'  src='"+url+"'></iframe>";
	return content;
}